package com.css.dzj.dzjap.modules.export.controller;

import com.alibaba.fastjson.JSON;
import com.css.aq.server.service.BaseService;
import com.css.dzj.dzjap.common.audit.service.SysAuditService;
import com.css.dzj.dzjap.common.util.Constant;
import com.css.dzj.dzjap.common.util.R;
import com.css.dzj.dzjap.modules.export.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/import")
public class ImportController {

    @Autowired
    private ImportService importService;
    @Autowired
    private SysAuditService sysAuditService;
    @Autowired
    private HttpServletRequest request;
    @PostMapping("/expertImport")
    public R expertImport(@RequestParam("file") MultipartFile file){
        String s="";
     try {
         String flag = importService.expertImport(file);
         if (!"0".equals(flag)) {
             R r = new R();
             r.put("code", 200);
             r.put("msg", "操作成功");
             r.ok().put("data", flag);
             sysAuditService.saveSuccessAudit("专家信用信息", Constant.EXPERTCRED,Constant.PT,Constant.IMPORT,s,request);
             return r;
         } else {
             return R.error("导入失败");
         }
     }catch (Exception e){
         sysAuditService.saveFailAudit("专家信用信息",Constant.EXPERTCRED,Constant.PT,Constant.IMPORT,s,e,request);
         return  R.error(e.getMessage());
     }

    }

}
